export class SpanRepresentation
{
  bold: boolean
  link: boolean
  italic: boolean
  monospace: boolean
  strikethrough: boolean
  start: number
  end: number

  constructor(
    bold?: boolean,
    link?: boolean,
    italic?: boolean,
    monospace?: boolean,
    strikethrough?: boolean,
    start?: number,
    end?: number
  ) {
    this.bold = bold;
    this.link = link;
    this.italic = italic;
    this.monospace = monospace;
    this.strikethrough = strikethrough;
    this.start = start;
    this.end = end;
  }



  isNotUseless(): boolean {
    return this.bold || this.link || this.italic || this.monospace || this.strikethrough
  }

  isEqualInSize(representation: SpanRepresentation): Boolean {
    return this.start == representation.start && this.end == representation.end
  }

  toString(): string {
    // assume we will not use '-'
    let str = ""
    str += (this.bold ? 1 : 0) + '-'
    str += (this.link ? 1 : 0) + '-'
    str += (this.italic ? 1 : 0) + '-'
    str += (this.monospace ? 1 : 0) + '-'
    str += (this.strikethrough ? 1 : 0) + '-'
    str += this.start.toString() + '-'
    str += this.end.toString() + '-'
    return str
  }
}

export function toSpans(str : string): SpanRepresentation {
  let strArr = str.split('-')
  let span: SpanRepresentation = new SpanRepresentation()
  span.bold = strArr[0] == "1" ? true : false
  span.link = strArr[1] == "1" ? true : false
  span.italic = strArr[2] == "1" ? true : false
  span.monospace = strArr[3] == "1" ? true : false
  span.strikethrough = strArr[4] == "1" ? true : false
  span.start = Number(strArr[5])
  span.end = Number(strArr[6])
  return span
}